package tst

//import java.lang.Integer as INT
//https://my.oschina.net/xiefeifeihu/blog/81104
//https://blog.csdn.net/asty9000/article/details/80399493
@groovy.transform.ToString
class DigitalType
{
	int num
	static {
		String.metaClass.asType {  Class c ->
			if (DigitalType == c) {
				DigitalType.DigitalTypefrom(delegate)
			}
			else if (BigDecimal == c)
			{
				DigitalType.BigDecimalfrom(delegate)
			}
			else {
				delegate.asType(c)
			}
		}
	}

	static DigitalType DigitalTypefrom(String text)
	{
		new DigitalType(num:Integer.valueOf(text));
	}
	
	static BigDecimal BigDecimalfrom(String text)
	{
		new BigDecimal (text);
		
	}
	
	static init() {}
}

DigitalType.init()
DigitalType i1 =  '123'.asType(DigitalType)
println i1
DigitalType i =  '456' as DigitalType
println i
def d1 =  '789'.asType(DigitalType)
println d1
//BigDecimal d2 = '234.567'
BigDecimal d2 = '234.567' as BigDecimal
println d2